
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>3.自己动手实现带校验的Form表单组件 · Gary的小窝</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Gary">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-solarizedlight.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="./" />
    
    
    <link rel="prev" href="../vue/2.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    写在前面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../leetcode/">
            
                <a href="../leetcode/">
            
                    
                    Leetcode之旅
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../leetcode/1.html">
            
                <a href="../leetcode/1.html">
            
                    
                    1.两数之和
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../leetcode/2.html">
            
                <a href="../leetcode/2.html">
            
                    
                    2.两数相加
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../leetcode/3.html">
            
                <a href="../leetcode/3.html">
            
                    
                    3.无重复字符的最长子串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../leetcode/4.html">
            
                <a href="../leetcode/4.html">
            
                    
                    4.寻找两个有序数组的中位数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../leetcode/6.html">
            
                <a href="../leetcode/6.html">
            
                    
                    6.Z字形变换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../leetcode/9.html">
            
                <a href="../leetcode/9.html">
            
                    
                    9.回文数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../leetcode/11.html">
            
                <a href="../leetcode/11.html">
            
                    
                    11.盛最多水的容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../leetcode/12.html">
            
                <a href="../leetcode/12.html">
            
                    
                    12.整数转罗马数字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../leetcode/13.html">
            
                <a href="../leetcode/13.html">
            
                    
                    13.罗马数字转整数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="../leetcode/14.html">
            
                <a href="../leetcode/14.html">
            
                    
                    14.最长公共前缀
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="../leetcode/322.html">
            
                <a href="../leetcode/322.html">
            
                    
                    322.零钱兑换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../leetcode/72.html">
            
                <a href="../leetcode/72.html">
            
                    
                    72.编辑距离
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../flutter/">
            
                <a href="../flutter/">
            
                    
                    Flutter从入门到放弃
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../flutter/dart1.html">
            
                <a href="../flutter/dart1.html">
            
                    
                    1.Dart语言(1)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../flutter/dart2.html">
            
                <a href="../flutter/dart2.html">
            
                    
                    2.Dart语言(2)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../flutter/widget1.html">
            
                <a href="../flutter/widget1.html">
            
                    
                    3.Flutter初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../flutter/containerText.html">
            
                <a href="../flutter/containerText.html">
            
                    
                    4.Container和Text组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../flutter/image.html">
            
                <a href="../flutter/image.html">
            
                    
                    5.Image组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../flutter/chapter2.html">
            
                <a href="../flutter/chapter2.html">
            
                    
                    6.Flutter 技术总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../vue/">
            
                <a href="../vue/">
            
                    
                    Vue组件精讲
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../vue/1.html">
            
                <a href="../vue/1.html">
            
                    
                    1.provide/inject
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../vue/2.html">
            
                <a href="../vue/2.html">
            
                    
                    2.手动实现broadcast和dispatch方法
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.3" data-path="form.html">
            
                <a href="form.html">
            
                    
                    3.自己动手实现带校验的Form表单组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="./">
            
                <a href="./">
            
                    
                    JavaScript进阶
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="proxy.html">
            
                <a href="proxy.html">
            
                    
                    1.Vue.js 3.0中的响应式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="el.html">
            
                <a href="el.html">
            
                    
                    2.Element UI 源码初探
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="bind.html">
            
                <a href="bind.html">
            
                    
                    3.bind的模拟实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="proto.html">
            
                <a href="proto.html">
            
                    
                    4.JS原型和原型链
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="call.html">
            
                <a href="call.html">
            
                    
                    5.模拟实现call和apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="ui.html">
            
                <a href="ui.html">
            
                    
                    6.使用Vue cli3搭建组件库并发布到 npm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="microFE.html">
            
                <a href="microFE.html">
            
                    
                    7.记一次基于qiankun的微前端的改造
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="git.html">
            
                <a href="git.html">
            
                    
                    8.Git的使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../vueLibrary/">
            
                <a href="../vueLibrary/">
            
                    
                    基于Vue的PC端的组件库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../vueLibrary/1.html">
            
                <a href="../vueLibrary/1.html">
            
                    
                    1.环境搭建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../life/">
            
                <a href="../life/">
            
                    
                    网事杂谈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../life/1.html">
            
                <a href="../life/1.html">
            
                    
                    1.周杰伦专辑赏析--叶惠美
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../life/2.html">
            
                <a href="../life/2.html">
            
                    
                    2.周杰伦专辑赏析--七里香
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >3.自己动手实现带校验的Form表单组件</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x4E00;&#x4E2A;&#x62E5;&#x6709;&#x6821;&#x9A8C;&#x529F;&#x80FD;&#x7684;form&#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;"><b></b>&#x4E00;&#x4E2A;&#x62E5;&#x6709;&#x6821;&#x9A8C;&#x529F;&#x80FD;&#x7684;Form&#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;</a></li><ul><li><span class="title-icon "></span><a href="#&#x80CC;&#x666F;"><b></b>&#x80CC;&#x666F;</a></li><li><span class="title-icon "></span><a href="#&#x52A8;&#x624B;&#x524D;&#x5148;&#x601D;&#x8003;"><b></b>&#x52A8;&#x624B;&#x524D;&#x5148;&#x601D;&#x8003;</a></li><li><span class="title-icon "></span><a href="#&#x5F00;&#x5E72;"><b></b>&#x5F00;&#x5E72;</a></li><ul><li><span class="title-icon "></span><a href="#input&#x7EC4;&#x4EF6;"><b></b>input&#x7EC4;&#x4EF6;</a></li></ul><li><span class="title-icon "></span><a href="#formitem"><b></b>FormItem</a></li><li><span class="title-icon "></span><a href="#&#x5F00;&#x59CB;&#x9A8C;&#x8BC1;"><b></b>&#x5F00;&#x59CB;&#x9A8C;&#x8BC1;</a></li><li><span class="title-icon "></span><a href="#&#x5B9E;&#x73B0;&#x5168;&#x5C40;&#x6821;&#x9A8C;&#x548C;&#x91CD;&#x7F6E;"><b></b>&#x5B9E;&#x73B0;&#x5168;&#x5C40;&#x6821;&#x9A8C;&#x548C;&#x91CD;&#x7F6E;</a></li></ul></ul></div><a href="#&#x4E00;&#x4E2A;&#x62E5;&#x6709;&#x6821;&#x9A8C;&#x529F;&#x80FD;&#x7684;form&#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="&#x4E00;&#x4E2A;&#x62E5;&#x6709;&#x6821;&#x9A8C;&#x529F;&#x80FD;&#x7684;form&#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;"><a name="&#x4E00;&#x4E2A;&#x62E5;&#x6709;&#x6821;&#x9A8C;&#x529F;&#x80FD;&#x7684;form&#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;" class="anchor-navigation-ex-anchor" href="#&#x4E00;&#x4E2A;&#x62E5;&#x6709;&#x6821;&#x9A8C;&#x529F;&#x80FD;&#x7684;form&#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E00;&#x4E2A;&#x62E5;&#x6709;&#x6821;&#x9A8C;&#x529F;&#x80FD;&#x7684;Form&#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;</h1>
<h2 id="&#x80CC;&#x666F;"><a name="&#x80CC;&#x666F;" class="anchor-navigation-ex-anchor" href="#&#x80CC;&#x666F;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x80CC;&#x666F;</h2>
<p>&#x8868;&#x5355;&#x7C7B;&#x7EC4;&#x4EF6;&#x5728;&#x9879;&#x76EE;&#x4E2D;&#x4F1A;&#x5927;&#x91CF;&#x4F7F;&#x7528;&#xFF0C;&#x6BD4;&#x5982;&#x8F93;&#x5165;&#x6846;&#xFF08;Input&#xFF09;&#x3001;&#x5355;&#x9009;&#xFF08;Radio&#xFF09;&#x3001;&#x591A;&#x9009;&#xFF08;Checkbox&#xFF09;&#x3001;&#x4E0B;&#x62C9;&#x9009;&#x62E9;&#x5668;&#xFF08;Select&#xFF09;&#x7B49;&#x3002;&#x5728;&#x4F7F;&#x7528;&#x8868;&#x5355;&#x7C7B;&#x7EC4;&#x4EF6;&#x65F6;&#xFF0C;&#x4E5F;&#x4F1A;&#x7ECF;&#x5E38;&#x7528;&#x5230;&#x6570;&#x636E;&#x6821;&#x9A8C;&#xFF0C;&#x5982;&#x679C;&#x6BCF;&#x6B21;&#x90FD;&#x5199;&#x6821;&#x9A8C;&#x7A0B;&#x5E8F;&#x6765;&#x5BF9;&#x6BCF;&#x4E00;&#x4E2A;&#x8868;&#x5355;&#x63A7;&#x4EF6;&#x6821;&#x9A8C;&#xFF0C;&#x4F1A;&#x5F88;&#x4F4E;&#x6548;&#xFF0C;&#x56E0;&#x6B64;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x80FD;&#x591F;&#x6821;&#x9A8C;&#x57FA;&#x7840;&#x8868;&#x5355;&#x63A7;&#x4EF6;&#x7684;&#x7EC4;&#x4EF6;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x672C;&#x8282;&#x8981;&#x5B8C;&#x6210;&#x7684; Form &#x7EC4;&#x4EF6;&#x3002;&#x4E00;&#x822C;&#x7684;&#x7EC4;&#x4EF6;&#x5E93;&#x90FD;&#x63D0;&#x4F9B;&#x4E86;&#x8FD9;&#x4E2A;&#x7EC4;&#x4EF6;&#xFF0C;&#x6BD4;&#x5982; ElementUI&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x5728;&#x4F7F;&#x7528;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x6709;&#x6CA1;&#x6709;&#x8FDB;&#x884C;&#x8FC7;&#x601D;&#x8003;&#xFF0C;&#x8FD9;&#x4E2A;&#x6821;&#x9A8C;&#x7A76;&#x7ADF;&#x662F;&#x600E;&#x4E48;&#x5B9E;&#x73B0;&#x7684;&#xFF1F;&#x672C;&#x7BC7;&#x6587;&#x7AE0;&#x5E26;&#x4F60;&#x4E00;&#x63A2;&#x7A76;&#x7ADF;&#x3002;</p>
<h2 id="&#x52A8;&#x624B;&#x524D;&#x5148;&#x601D;&#x8003;"><a name="&#x52A8;&#x624B;&#x524D;&#x5148;&#x601D;&#x8003;" class="anchor-navigation-ex-anchor" href="#&#x52A8;&#x624B;&#x524D;&#x5148;&#x601D;&#x8003;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x52A8;&#x624B;&#x524D;&#x5148;&#x601D;&#x8003;</h2>
<p>&#x6211;&#x4EEC;&#x5728;&#x4F7F;&#x7528;ElementUI&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x90FD;&#x5F88;&#x719F;&#x6089;&#x4E86;&#xFF0C;&#x5E94;&#x8BE5;&#x8C03;&#x7528;&#x7684;&#x65F6;&#x5019;&#x5E94;&#x8BE5;&#x957F;&#x8FD9;&#x4E2A;&#x6837;&#x5B50;</p>
<pre class="language-"><code class="lang-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>el-form</span> <span class="token attr-name">:model</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>formModel<span class="token punctuation">&quot;</span></span> <span class="token attr-name">:rules</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>ruleValidate<span class="token punctuation">&quot;</span></span> <span class="token attr-name">ref</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>form<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>el-form-item</span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>&#x7528;&#x6237;&#x540D;<span class="token punctuation">&quot;</span></span> <span class="token attr-name">prop</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>username<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>el-input</span> <span class="token attr-name">v-model</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>formModel.username<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>el-input</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>el-form-item</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>el-form-item</span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>&#x5BC6;&#x7801;<span class="token punctuation">&quot;</span></span> <span class="token attr-name">prop</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>password<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>el-input</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>password<span class="token punctuation">&quot;</span></span> <span class="token attr-name">v-model</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>formModel.password<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>el-input</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>el-form-item</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>el-form</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>  
  <span class="token function">data</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span><span class="token punctuation">{</span>
        formModel<span class="token punctuation">:</span><span class="token punctuation">{</span>
           username<span class="token punctuation">:</span> <span class="token string">&apos;&apos;</span><span class="token punctuation">,</span>
           password<span class="token punctuation">:</span> <span class="token string">&apos;&apos;</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        ruleValidate<span class="token punctuation">:</span> <span class="token punctuation">{</span>
          username<span class="token punctuation">:</span> <span class="token punctuation">[</span>
            <span class="token punctuation">{</span> required<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> message<span class="token punctuation">:</span> <span class="token string">&apos;&#x7528;&#x6237;&#x540D;&#x4E0D;&#x80FD;&#x4E3A;&#x7A7A;&apos;</span><span class="token punctuation">,</span> trigger<span class="token punctuation">:</span> <span class="token string">&apos;blur&apos;</span> <span class="token punctuation">}</span>
          <span class="token punctuation">]</span><span class="token punctuation">,</span>
          password<span class="token punctuation">:</span> <span class="token punctuation">[</span>
            <span class="token punctuation">{</span> required<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> message<span class="token punctuation">:</span> <span class="token string">&apos;&#x5BC6;&#x7801;&#x4E0D;&#x80FD;&#x4E3A;&#x7A7A;&apos;</span><span class="token punctuation">,</span> trigger<span class="token punctuation">:</span> <span class="token string">&apos;blur&apos;</span> <span class="token punctuation">}</span>
          <span class="token punctuation">]</span><span class="token punctuation">,</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token function">mounted</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  methods<span class="token punctuation">:</span><span class="token punctuation">{</span>
       <span class="token function">handleSubmit</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>$refs<span class="token punctuation">.</span>form<span class="token punctuation">.</span><span class="token function">validate</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">valid</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>valid<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    window<span class="token punctuation">.</span><span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">&apos;&#x63D0;&#x4EA4;&#x6210;&#x529F;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                    window<span class="token punctuation">.</span><span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">&apos;&#x8868;&#x5355;&#x6821;&#x9A8C;&#x5931;&#x8D25;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token function">handleReset</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>$refs<span class="token punctuation">.</span>form<span class="token punctuation">.</span><span class="token function">resetFields</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<p>&#x53EF;&#x4EE5;&#x5206;&#x6790;&#x51FA;&#x6765; &#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;form&#x8868;&#x5355; &#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x6709;&#x4E09;&#x4E2A;&#x7EC4;&#x4EF6;&#x7EC4;&#x6210;&#x3002;</p>
<ul>
<li>Form&#x7EC4;&#x4EF6;</li>
<li>FormIten&#x7EC4;&#x4EF6;</li>
<li>Input&#x7EC4;&#x4EF6;</li>
</ul>
<p>&#x5728;&#x8FD9;&#x4E09;&#x4E2A;&#x7EC4;&#x4EF6;&#x4E2D;&#xFF0C;&#x4F1A;&#x7ED1;&#x5B9A;&#x4E0D;&#x540C;&#x7684;&#x5C5E;&#x6027;&#xFF1A;</p>
<ol>
<li>Form&#x7EC4;&#x4EF6; (model,rules,ref)<ul>
<li>model &#x8868;&#x5355;&#x63A7;&#x4EF6;&#x7ED1;&#x5B9A;&#x7684;&#x6570;&#x636E;&#x5BF9;&#x8C61;&#xFF0C;&#x5728;&#x6821;&#x9A8C;&#x6216;&#x91CD;&#x7F6E;&#x65F6;&#x4F1A;&#x8BBF;&#x95EE;&#x8BE5;&#x6570;&#x636E;&#x5BF9;&#x8C61;&#x4E0B;&#x5BF9;&#x5E94;&#x7684;&#x8868;&#x5355;&#x6570;&#x636E;&#xFF0C;&#x7C7B;&#x578B;&#x4E3A; Object&#x3002;</li>
<li>rules &#x8868;&#x5355;&#x9A8C;&#x8BC1;&#x89C4;&#x5219;&#xFF0C;&#x5373;&#x4E0A;&#x9762;&#x4ECB;&#x7ECD;&#x7684; async-validator &#x6240;&#x4F7F;&#x7528;&#x7684;&#x6821;&#x9A8C;&#x89C4;&#x5219;&#xFF0C;&#x7C7B;&#x578B;&#x4E3A; Object&#x3002;</li>
<li>ref &#x5F15;&#x7528;</li>
</ul>
</li>
<li>FormIten&#x7EC4;&#x4EF6;(label,prop)<ul>
<li>label &#x5355;&#x4E2A;&#x8868;&#x5355;&#x7EC4;&#x4EF6;&#x7684;&#x6807;&#x7B7E;&#x6587;&#x672C;&#xFF0C;&#x7C7B;&#x4F3C;&#x539F;&#x751F;&#x7684; <label> &#x5143;&#x7D20;&#xFF0C;&#x7C7B;&#x578B;&#x4E3A; String&#x3002;</label></li>
<li>prop &#x5BF9;&#x5E94;&#x8868;&#x5355;&#x57DF; Form &#x7EC4;&#x4EF6; model &#x91CC;&#x7684;&#x5B57;&#x6BB5;&#xFF0C;&#x7528;&#x4E8E;&#x5728;&#x6821;&#x9A8C;&#x6216;&#x91CD;&#x7F6E;&#x65F6;&#x8BBF;&#x95EE;&#x8868;&#x5355;&#x7EC4;&#x4EF6;&#x7ED1;&#x5B9A;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x7C7B;&#x578B;&#x4E3A; String&#x3002;</li>
</ul>
</li>
<li>Input&#x7EC4;&#x4EF6;(type,v-model)<ul>
<li>type  input&#x539F;&#x751F;&#x5C5E;&#x6027; input &#x7684;&#x7C7B;&#x578B;</li>
<li>v-model &#x53CC;&#x5411;&#x7ED1;&#x5B9A; input&#x4E2D;&#x7684;&#x503C;</li>
</ul>
</li>
</ol>
<p>&#x6700;&#x540E;&#x4F1A;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x6821;&#x9A8C;&#x7684;Form&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x5206;&#x6790;&#x4E00;&#x4E0B;</p>
<ol>
<li>&#x6211;&#x4EEC;&#x5728;Input &#x7EC4;&#x4EF6;&#x4E2D;&#x53BB;&#x8F93;&#x5165;&#x5185;&#x5BB9; &#x5F53;change&#x6216;&#x8005;blur&#x4E8B;&#x4EF6;&#x89E6;&#x53D1;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x628A;&#x4E8B;&#x4EF6;&#x4F20;&#x9012;&#x7ED9;FormItem&#xFF0C;&#x8BA9;FromItem &#x53BB;&#x8FDB;&#x884C;&#x68C0;&#x9A8C;</li>
<li>Form&#x7EC4;&#x4EF6;&#x662F;&#x6709;&#x5168;&#x5C40;&#x6821;&#x9A8C;&#x548C;&#x91CD;&#x7F6E;&#x7684;&#x65B9;&#x6CD5;&#x7684;&#xFF0C;&#x9700;&#x8981;&#x628A;form&#x5F53;&#x4E2D;&#x6240;&#x6709;item&#x8FDB;&#x884C;&#x4E00;&#x8D77;&#x6821;&#x9A8C;&#xFF0C;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;</li>
<li>&#x5173;&#x4E8E;&#x6821;&#x9A8C;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x7528;&#x5230;&#x4E00;&#x4E2A;&#x5F00;&#x6E90;&#x5E93;&#xFF1A;async-validator&#xFF0C;&#x57FA;&#x672C;&#x73B0;&#x5728;&#x4E3B;&#x6D41;&#x7684;&#x7EC4;&#x4EF6;&#x5E93;&#x90FD;&#x662F;&#x57FA;&#x4E8E;&#x5B83;&#x505A;&#x7684;&#x6821;&#x9A8C;&#x3002;&#x4F7F;&#x7528;&#x5B83;&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x53EA;&#x9700;&#x6309;&#x8981;&#x6C42;&#x5199;&#x597D;&#x4E00;&#x4E2A;&#x6821;&#x9A8C;&#x89C4;&#x5219;&#x5C31;&#x597D;&#xFF0C;&#x6BD4;&#x5982;&#xFF1A;<pre class="language-"><code>[
{ required: true, message: &apos;&#x4E0D;&#x80FD;&#x4E3A;&#x7A7A;&apos;, trigger: &apos;blur&apos; },
{ type: &apos;email&apos;, message: &apos;&#x90AE;&#x7BB1;&#x683C;&#x5F0F;&#x4E0D;&#x6B63;&#x786E;&apos;, trigger: &apos;blur&apos; }
]
</code></pre></li>
</ol>
<h2 id="&#x5F00;&#x5E72;"><a name="&#x5F00;&#x5E72;" class="anchor-navigation-ex-anchor" href="#&#x5F00;&#x5E72;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5F00;&#x5E72;</h2>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6839;&#x636E;&#x4E0A;&#x9762;&#x7684;&#x8BBE;&#x8BA1; &#x5199;&#x51FA;&#x57FA;&#x7840;&#x4EE3;&#x7801;
input.vue</p>
<pre class="language-"><code class="lang-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">:type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>type<span class="token punctuation">&quot;</span></span>  <span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    name<span class="token punctuation">:</span> <span class="token string">&apos;faInput&apos;</span><span class="token punctuation">,</span>
    props<span class="token punctuation">:</span><span class="token punctuation">{</span>
        type<span class="token punctuation">:</span><span class="token punctuation">{</span>
           type<span class="token punctuation">:</span>String<span class="token punctuation">,</span>
           <span class="token keyword">default</span><span class="token punctuation">:</span><span class="token string">&apos;text&apos;</span> 
        <span class="token punctuation">}</span>

    <span class="token punctuation">}</span><span class="token punctuation">,</span>
     <span class="token function">data</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token punctuation">{</span>

        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>

    methods<span class="token punctuation">:</span><span class="token punctuation">{</span>

    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<h3 id="input&#x7EC4;&#x4EF6;"><a name="input&#x7EC4;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#input&#x7EC4;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>input&#x7EC4;&#x4EF6;</h3>
<p>&#x5728;&#x8FD9;&#x4E2A;input&#x4E2D;&#x6211;&#x4EEC;&#x8981;&#x5B9E;&#x73B0;&#x53CC;&#x5411;&#x7ED1;&#x5B9A;v-model&#xFF0C;&#x5176;&#x5B9E;v-model&#x662F;&#x4E2A;&#x8BED;&#x6CD5;&#x7CD6;&#xFF0C;&#x5728;input&#x7EC4;&#x4EF6;&#x5185; &#x9700;&#x8981;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;value&#x7684;&#x5C5E;&#x6027;&#x548C;input&#x65B9;&#x6CD5;&#xFF0C;&#x5E76;&#x4E14;&#x5C06;input&#x7684;&#x503C;&#x4F20;&#x5230;&#x7236;&#x7EC4;&#x4EF6;&#x53BB;&#x3002;&#x56E0;&#x4E3A;Form&#x6821;&#x9A8C;&#x652F;&#x6301;blur change &#x4E24;&#x79CD;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x8FD8;&#x8981;&#x518D;blur&#x4E8B;&#x4EF6;&#x548C;input&#x65B9;&#x6CD5;&#x4E2D;&#x53BB;&#x544A;&#x8BC9;&#x7236;&#x7EC4;&#x4EF6;&#xFF0C;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x6821;&#x9A8C;&#xFF0C;&#x5728;&#x4E8B;&#x4EF6;&#x4F20;&#x9012;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x7684;&#x662F;&#x4E0A;&#x4E00;&#x8282;&#x7684;broadcast&#x548C;dispatch&#x7684;mixin&#x3002; &#x4EE3;&#x7801;&#x5982;&#x4E0B;</p>
<pre class="language-"><code class="lang-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">:type</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>type<span class="token punctuation">&quot;</span></span> <span class="token attr-name">:value</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>currentValue<span class="token punctuation">&quot;</span></span> <span class="token attr-name">@input</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>input<span class="token punctuation">&quot;</span></span> <span class="token attr-name">@blur</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>handleBlur<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
<span class="token keyword">import</span> Emitter <span class="token keyword">from</span> <span class="token string">&apos;./emiter&apos;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    name<span class="token punctuation">:</span> <span class="token string">&apos;faInput&apos;</span><span class="token punctuation">,</span>
    mixins<span class="token punctuation">:</span> <span class="token punctuation">[</span> Emitter <span class="token punctuation">]</span><span class="token punctuation">,</span>
    props<span class="token punctuation">:</span><span class="token punctuation">{</span>
        type<span class="token punctuation">:</span><span class="token punctuation">{</span>
           type<span class="token punctuation">:</span>String<span class="token punctuation">,</span>
           <span class="token keyword">default</span><span class="token punctuation">:</span><span class="token string">&apos;text&apos;</span> 
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        value<span class="token punctuation">:</span><span class="token punctuation">{</span>
           type<span class="token punctuation">:</span>String<span class="token punctuation">,</span>
           <span class="token keyword">default</span><span class="token punctuation">:</span><span class="token string">&apos;text&apos;</span> 
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
     <span class="token function">data</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token punctuation">{</span>
            currentValue<span class="token punctuation">:</span> <span class="token keyword">this</span><span class="token punctuation">.</span>value
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    watch<span class="token punctuation">:</span> <span class="token punctuation">{</span>
        <span class="token function">value</span> <span class="token punctuation">(</span><span class="token parameter">val</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>currentValue <span class="token operator">=</span> val<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    methods<span class="token punctuation">:</span><span class="token punctuation">{</span>
        <span class="token function">input</span><span class="token punctuation">(</span><span class="token parameter">event</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">const</span> value <span class="token operator">=</span> event<span class="token punctuation">.</span>target<span class="token punctuation">.</span>value<span class="token punctuation">;</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>currentValue <span class="token operator">=</span> value<span class="token punctuation">;</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$emit</span><span class="token punctuation">(</span><span class="token string">&apos;input&apos;</span><span class="token punctuation">,</span> value<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&apos;faFormItem&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;on-form-change&apos;</span><span class="token punctuation">,</span> value<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token function">handleBlur</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&apos;faFormItem&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;on-form-blur&apos;</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>currentValue<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">

</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<p>input &#x7EC4;&#x4EF6;&#x4E2D;&#xFF0C;&#x7ED1;&#x5B9A;&#x5728; <code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span><span class="token punctuation">&gt;</span></span></code> &#x5143;&#x7D20;&#x4E0A;&#x7684;&#x539F;&#x751F;&#x4E8B;&#x4EF6; @input&#xFF0C;&#x6BCF;&#x5F53;&#x8F93;&#x5165;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#xFF0C;&#x90FD;&#x4F1A;&#x8C03;&#x7528;&#x53E5;&#x67C4; input&#xFF0C;&#x5E76;&#x901A;&#x8FC7; dispatch &#x65B9;&#x6CD5;&#x5411;&#x4E0A;&#x7EA7;&#x7684; FormItem &#x7EC4;&#x4EF6;&#x6D3E;&#x53D1;&#x81EA;&#x5B9A;&#x4E49;&#x4E8B;&#x4EF6; on-form-change&#xFF1B;&#x540C;&#x7406;&#xFF0C;&#x7ED1;&#x5B9A;&#x7684;&#x539F;&#x751F;&#x4E8B;&#x4EF6; @blur &#x4F1A;&#x5728; input &#x5931;&#x7126;&#x65F6;&#x89E6;&#x53D1;&#xFF0C;&#x5E76;&#x4F20;&#x9012;&#x4E8B;&#x4EF6; on-form-blur&#x3002;</p>
<h2 id="formitem"><a name="formitem" class="anchor-navigation-ex-anchor" href="#formitem"><i class="fa fa-link" aria-hidden="true"></i></a>FormItem</h2>
<p>&#x57FA;&#x672C;&#x7684;input&#x7EC4;&#x4EF6;&#x51FA;&#x6765;&#x4E86;&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x8981;&#x505A;&#x7684;&#xFF0C;&#x662F;&#x5728; FormItem &#x4E2D;&#x76D1;&#x542C;&#x6765;&#x81EA; Input &#x7EC4;&#x4EF6;&#x6D3E;&#x53D1;&#x7684;&#x81EA;&#x5B9A;&#x4E49;&#x4E8B;&#x4EF6;&#x3002;&#x8FD9;&#x91CC;&#x53EF;&#x4EE5;&#x5728; mounted &#x4E2D;&#x76D1;&#x542C;&#xFF0C;&#x56E0;&#x4E3A;&#x4F60;&#x7684;&#x624B;&#x901F;&#x8FDC;&#x8D76;&#x4E0D;&#x4E0A;&#x7EC4;&#x4EF6;&#x6E32;&#x67D3;&#x7684;&#x901F;&#x5EA6;&#xFF0C;&#x4E0D;&#x8FC7;&#x5728; created &#x4E2D;&#x76D1;&#x542C;&#x4E5F;&#x662F;&#x6CA1;&#x4EFB;&#x4F55;&#x95EE;&#x9898;&#x7684;&#x3002;&#x76F8;&#x5173;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-js"><span class="token comment">// form-item.vue&#xFF0C;&#x90E8;&#x5206;&#x4EE3;&#x7801;&#x7701;&#x7565;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  methods<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token function">setRules</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$on</span><span class="token punctuation">(</span><span class="token string">&apos;on-form-blur&apos;</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>onFieldBlur<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$on</span><span class="token punctuation">(</span><span class="token string">&apos;on-form-change&apos;</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>onFieldChange<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token function">mounted</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment">//&#x53EA;&#x6709;formItem&#x4E2D;&#x7684;prop&#x5B58;&#x5728; &#x624D;&#x4F1A;&#x6267;&#x884C;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>prop<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&apos;faForm&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;on-form-item-add&apos;</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setRules</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5728;item&#x7EC4;&#x4EF6;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5148;&#x76D1;&#x542C;&#x4E86; input&#x7EC4;&#x4EF6; &#x4F20;&#x8FC7;&#x6765;&#x7684;&#x4E8B;&#x4EF6;&#xFF0C;&#x4F7F;&#x7528;&#x4E24;&#x4E2A;&#x51FD;&#x6570;&#x6765;&#x76D1;&#x542C;&#xFF0C;&#x5F53; onFieldBlur &#x6216; onFieldChange &#x51FD;&#x6570;&#x89E6;&#x53D1;&#x65F6;&#xFF0C;&#x5C31;&#x610F;&#x5473;&#x7740; FormItem &#x8981;&#x5BF9;&#x5F53;&#x524D;&#x7684;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x4E00;&#x6B21;&#x6821;&#x9A8C;&#x3002;</p>
<p>&#x5F53;&#x524D;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x6307;&#x7684;&#x5C31;&#x662F;&#x901A;&#x8FC7;&#x8868;&#x5355;&#x57DF; Form &#x4E2D;&#x5B9A;&#x4E49;&#x7684; props&#xFF1A;model&#xFF0C;&#x7ED3;&#x5408;&#x5F53;&#x524D; FormItem &#x5B9A;&#x4E49;&#x7684; props&#xFF1A;prop &#x6765;&#x786E;&#x5B9A;&#x7684;&#x6570;&#x636E;&#x3002;
&#x56E0;&#x4E3A; FormItem &#x4E2D;&#x53EA;&#x5B9A;&#x4E49;&#x4E86;&#x6570;&#x636E;&#x6E90;&#x7684;&#x67D0;&#x4E2A; key &#x540D;&#x79F0;&#xFF08;&#x5373;&#x5C5E;&#x6027; prop&#xFF09;&#xFF0C;&#x8981;&#x62FF;&#x5230; Form &#x4E2D; model &#x91CC;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x9700;&#x8981;&#x7528;&#x5230; provide / inject&#x3002;&#x6240;&#x4EE5;&#x5728; Form &#x4E2D;&#xFF0C;&#x628A;&#x6574;&#x4E2A;&#x5B9E;&#x4F8B;&#xFF08;this&#xFF09;&#x5411;&#x4E0B;&#x63D0;&#x4F9B;&#xFF0C;&#x5E76;&#x5728; FormItem &#x4E2D;&#x6CE8;&#x5165;&#xFF1A;</p>
<pre class="language-"><code class="lang-js"><span class="token comment">// form.vue&#xFF0C;&#x90E8;&#x5206;&#x4EE3;&#x7801;&#x7701;&#x7565;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  <span class="token function">provide</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">{</span>
      form <span class="token punctuation">:</span> <span class="token keyword">this</span>
    <span class="token punctuation">}</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token comment">// form-item.vue&#xFF0C;&#x90E8;&#x5206;&#x4EE3;&#x7801;&#x7701;&#x7565;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  inject<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&apos;form&apos;</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5E76;&#x4E14;&#x5728;item&#x7EC4;&#x5EFA;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x628A;&#x5F53;&#x524D;&#x5B9E;&#x4F8B;&#xFF0C;&#x7EE7;&#x7EED;&#x5411;&#x4E0A;&#x4F20;&#x9012;&#xFF0C;&#x8BA9;form&#x7EC4;&#x4EF6;&#x7F13;&#x5B58;&#x6240;&#x6709;item&#x7EC4;&#x4EF6;&#xFF0C;&#x505A;&#x5168;&#x5C40;&#x7684;&#x6821;&#x9A8C;&#x4F7F;&#x7528;&#x3002;</p>
<pre class="language-"><code class="lang-js"><span class="token keyword">import</span> Emitter <span class="token keyword">from</span> <span class="token string">&apos;../../mixins/emitter.js&apos;</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  name<span class="token punctuation">:</span> <span class="token string">&apos;faFormItem&apos;</span><span class="token punctuation">,</span>
  mixins<span class="token punctuation">:</span> <span class="token punctuation">[</span> Emitter <span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token comment">// &#x7EC4;&#x4EF6;&#x6E32;&#x67D3;&#x65F6;&#xFF0C;&#x5C06;&#x5B9E;&#x4F8B;&#x7F13;&#x5B58;&#x5728; Form &#x4E2D;</span>
  <span class="token function">mounted</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// &#x5982;&#x679C;&#x6CA1;&#x6709;&#x4F20;&#x5165; prop&#xFF0C;&#x5219;&#x65E0;&#x9700;&#x6821;&#x9A8C;&#xFF0C;&#x4E5F;&#x5C31;&#x65E0;&#x9700;&#x7F13;&#x5B58;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>prop<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&apos;faForm&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;on-form-item-add&apos;</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token comment">// &#x7EC4;&#x4EF6;&#x9500;&#x6BC1;&#x524D;&#xFF0C;&#x5C06;&#x5B9E;&#x4F8B;&#x4ECE; Form &#x7684;&#x7F13;&#x5B58;&#x4E2D;&#x79FB;&#x9664;</span>
  <span class="token function">beforeDestroy</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&apos;faForm&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;on-form-item-remove&apos;</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#x5C31;&#x662F;&#x6B63;&#x83DC;&#x4E86;</p>
<h2 id="&#x5F00;&#x59CB;&#x9A8C;&#x8BC1;"><a name="&#x5F00;&#x59CB;&#x9A8C;&#x8BC1;" class="anchor-navigation-ex-anchor" href="#&#x5F00;&#x59CB;&#x9A8C;&#x8BC1;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5F00;&#x59CB;&#x9A8C;&#x8BC1;</h2>
<p>blur &#x548C; change &#x4E8B;&#x4EF6;&#x90FD;&#x4F1A;&#x89E6;&#x53D1;&#x6821;&#x9A8C;&#xFF0C;&#x5B83;&#x4EEC;&#x8C03;&#x7528;&#x540C;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#xFF0C;&#x53EA;&#x662F;&#x53C2;&#x6570;&#x4E0D;&#x540C;&#x3002;&#x76F8;&#x5173;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-js"><span class="token comment">// form-item.vue&#xFF0C;&#x90E8;&#x5206;&#x4EE3;&#x7801;&#x7701;&#x7565;</span>
<span class="token keyword">import</span> AsyncValidator <span class="token keyword">from</span> <span class="token string">&apos;async-validator&apos;</span><span class="token punctuation">;</span>

<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  inject<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">&apos;form&apos;</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
  props<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    prop<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      type<span class="token punctuation">:</span> String
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token function">data</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">{</span>
      validateState<span class="token punctuation">:</span> <span class="token string">&apos;&apos;</span><span class="token punctuation">,</span>  <span class="token comment">// &#x6821;&#x9A8C;&#x72B6;&#x6001;</span>
      validateMessage<span class="token punctuation">:</span> <span class="token string">&apos;&apos;</span><span class="token punctuation">,</span>  <span class="token comment">// &#x6821;&#x9A8C;&#x4E0D;&#x901A;&#x8FC7;&#x65F6;&#x7684;&#x63D0;&#x793A;&#x4FE1;&#x606F;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  computed<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token comment">// &#x4ECE; Form &#x7684; model &#x4E2D;&#x52A8;&#x6001;&#x5F97;&#x5230;&#x5F53;&#x524D;&#x8868;&#x5355;&#x7EC4;&#x4EF6;&#x7684;&#x6570;&#x636E;</span>
    <span class="token function">fieldValue</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>form<span class="token punctuation">.</span>model<span class="token punctuation">[</span><span class="token keyword">this</span><span class="token punctuation">.</span>prop<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  methods<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token comment">// &#x4ECE; Form &#x7684; rules &#x5C5E;&#x6027;&#x4E2D;&#xFF0C;&#x83B7;&#x53D6;&#x5F53;&#x524D; FormItem &#x7684;&#x6821;&#x9A8C;&#x89C4;&#x5219;</span>
    <span class="token function">getRules</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">let</span> formRules <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>form<span class="token punctuation">.</span>rules<span class="token punctuation">;</span>

      formRules <span class="token operator">=</span> formRules <span class="token operator">?</span> formRules<span class="token punctuation">[</span><span class="token keyword">this</span><span class="token punctuation">.</span>prop<span class="token punctuation">]</span> <span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

      <span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span>formRules <span class="token operator">||</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">// &#x53EA;&#x652F;&#x6301; blur &#x548C; change&#xFF0C;&#x6240;&#x4EE5;&#x8FC7;&#x6EE4;&#x51FA;&#x7B26;&#x5408;&#x8981;&#x6C42;&#x7684; rule &#x89C4;&#x5219;</span>
    <span class="token function">getFilteredRule</span> <span class="token punctuation">(</span><span class="token parameter">trigger</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">const</span> rules <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getRules</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">return</span> rules<span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token parameter">rule</span> <span class="token operator">=&gt;</span> <span class="token operator">!</span>rule<span class="token punctuation">.</span>trigger <span class="token operator">||</span> rule<span class="token punctuation">.</span>trigger<span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span>trigger<span class="token punctuation">)</span> <span class="token operator">!==</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">/**
     * &#x6821;&#x9A8C;&#x6570;&#x636E;
     * @param trigger &#x6821;&#x9A8C;&#x7C7B;&#x578B;
     * @param callback &#x56DE;&#x8C03;&#x51FD;&#x6570;
     */</span>
    <span class="token function">validate</span><span class="token punctuation">(</span>trigger<span class="token punctuation">,</span> <span class="token function-variable function">callback</span> <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">let</span> rules <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getFilteredRule</span><span class="token punctuation">(</span>trigger<span class="token punctuation">)</span><span class="token punctuation">;</span>

      <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>rules <span class="token operator">||</span> rules<span class="token punctuation">.</span>length <span class="token operator">===</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>

      <span class="token comment">// &#x8BBE;&#x7F6E;&#x72B6;&#x6001;&#x4E3A;&#x6821;&#x9A8C;&#x4E2D;</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span>validateState <span class="token operator">=</span> <span class="token string">&apos;validating&apos;</span><span class="token punctuation">;</span>

      <span class="token comment">// &#x4EE5;&#x4E0B;&#x4E3A; async-validator &#x5E93;&#x7684;&#x8C03;&#x7528;&#x65B9;&#x6CD5;</span>
      <span class="token keyword">let</span> descriptor <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
      descriptor<span class="token punctuation">[</span><span class="token keyword">this</span><span class="token punctuation">.</span>prop<span class="token punctuation">]</span> <span class="token operator">=</span> rules<span class="token punctuation">;</span>

      <span class="token keyword">const</span> validator <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">AsyncValidator</span><span class="token punctuation">(</span>descriptor<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token keyword">let</span> model <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>

      model<span class="token punctuation">[</span><span class="token keyword">this</span><span class="token punctuation">.</span>prop<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>fieldValue<span class="token punctuation">;</span>

      validator<span class="token punctuation">.</span><span class="token function">validate</span><span class="token punctuation">(</span>model<span class="token punctuation">,</span> <span class="token punctuation">{</span> firstFields<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token parameter">errors</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>validateState <span class="token operator">=</span> <span class="token operator">!</span>errors <span class="token operator">?</span> <span class="token string">&apos;success&apos;</span> <span class="token punctuation">:</span> <span class="token string">&apos;error&apos;</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>validateMessage <span class="token operator">=</span> errors <span class="token operator">?</span> errors<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>message <span class="token punctuation">:</span> <span class="token string">&apos;&apos;</span><span class="token punctuation">;</span>

        <span class="token function">callback</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>validateMessage<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function">onFieldBlur</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">validate</span><span class="token punctuation">(</span><span class="token string">&apos;blur&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function">onFieldChange</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">validate</span><span class="token punctuation">(</span><span class="token string">&apos;change&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5728; FormItem &#x7684; validate() &#x65B9;&#x6CD5;&#x4E2D;&#xFF0C;&#x6700;&#x7EC8;&#x505A;&#x4E86;&#x4E24;&#x4EF6;&#x4E8B;&#xFF1A;</p>
<ul>
<li><p>&#x8BBE;&#x7F6E;&#x4E86;&#x5F53;&#x524D;&#x7684;&#x6821;&#x9A8C;&#x72B6;&#x6001; validateState &#x548C;&#x6821;&#x9A8C;&#x4E0D;&#x901A;&#x8FC7;&#x63D0;&#x793A;&#x4FE1;&#x606F; validateMessage&#xFF08;&#x901A;&#x8FC7;&#x503C;&#x4E3A;&#x7A7A;&#xFF09;&#xFF1B;</p>
</li>
<li><p>&#x5C06; validateMessage &#x901A;&#x8FC7;&#x56DE;&#x8C03; callback &#x4F20;&#x9012;&#x7ED9;&#x8C03;&#x7528;&#x8005;&#xFF0C;&#x8FD9;&#x91CC;&#x7684;&#x8C03;&#x7528;&#x8005;&#x662F; onFieldBlur &#x548C; onFieldChange&#xFF0C;&#x5B83;&#x4EEC;&#x53EA;&#x4F20;&#x5165;&#x4E86;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570; trigger&#xFF0C;callback &#x5E76;&#x672A;&#x4F20;&#x5165;&#xFF0C;&#x56E0;&#x6B64;&#x4E5F;&#x4E0D;&#x4F1A;&#x89E6;&#x53D1;&#x56DE;&#x8C03;&#xFF0C;&#x800C;&#x8FD9;&#x4E2A;&#x56DE;&#x8C03;&#x4E3B;&#x8981;&#x662F;&#x7ED9; Form &#x7528;&#x7684;&#xFF0C;&#x56E0;&#x4E3A; Form &#x4E2D;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x63D0;&#x4EA4;&#x6309;&#x94AE;&#x4E00;&#x6B21;&#x6027;&#x6821;&#x9A8C;&#x6240;&#x6709;&#x7684; FormItem&#xFF08;&#x540E;&#x6587;&#x4F1A;&#x4ECB;&#x7ECD;&#xFF09;&#x8FD9;&#x91CC;&#x53EA;&#x662F;&#x8868;&#x5355;&#x7EC4;&#x4EF6;&#x89E6;&#x53D1;&#x4E8B;&#x4EF6;&#x65F6;&#xFF0C;&#x5BF9;&#x5F53;&#x524D; FormItem &#x505A;&#x6821;&#x9A8C;&#x3002;</p>
</li>
</ul>
<p>&#x9664;&#x4E86;&#x6821;&#x9A8C;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x5BF9;&#x5F53;&#x524D;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x91CD;&#x7F6E;&#x3002;&#x91CD;&#x7F6E;&#x662F;&#x6307;&#x5C06;&#x8868;&#x5355;&#x7EC4;&#x4EF6;&#x7684;&#x6570;&#x636E;&#x8FD8;&#x539F;&#x5230;&#x6700;&#x521D;&#x7ED1;&#x5B9A;&#x7684;&#x503C;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x6E05;&#x7A7A;&#xFF0C;&#x56E0;&#x6B64;&#x9700;&#x8981;&#x9884;&#x5148;&#x7F13;&#x5B58;&#x4E00;&#x4EFD;&#x521D;&#x59CB;&#x503C;&#x3002;&#x540C;&#x65F6;&#x6211;&#x4EEC;&#x5C06;&#x6821;&#x9A8C;&#x4FE1;&#x606F;&#x4E5F;&#x663E;&#x793A;&#x5728;&#x6A21;&#x677F;&#x4E2D;&#xFF0C;&#x5E76;&#x52A0;&#x4E00;&#x4E9B;&#x6837;&#x5F0F;&#x3002;&#x76F8;&#x5173;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-html"><span class="token comment">&lt;!-- form-item.vue&#xFF0C;&#x90E8;&#x5206;&#x4EE3;&#x7801;&#x7701;&#x7565; --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">v-if</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>label<span class="token punctuation">&quot;</span></span> <span class="token attr-name">:class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>{ &apos;form-item-label-required&apos;: isRequired }<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>{{ label }}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>slot</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>slot</span><span class="token punctuation">&gt;</span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">v-if</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>validateState === &apos;error&apos;<span class="token punctuation">&quot;</span></span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>form-item-message<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>{{ validateMessage }}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
  <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    props<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      label<span class="token punctuation">:</span> <span class="token punctuation">{</span>
        type<span class="token punctuation">:</span> String<span class="token punctuation">,</span>
        <span class="token keyword">default</span><span class="token punctuation">:</span> <span class="token string">&apos;&apos;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      prop<span class="token punctuation">:</span> <span class="token punctuation">{</span>
        type<span class="token punctuation">:</span> String
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function">data</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token punctuation">{</span>
        isRequired<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>  <span class="token comment">// &#x662F;&#x5426;&#x4E3A;&#x5FC5;&#x586B;</span>
        validateState<span class="token punctuation">:</span> <span class="token string">&apos;&apos;</span><span class="token punctuation">,</span>  <span class="token comment">// &#x6821;&#x9A8C;&#x72B6;&#x6001;</span>
        validateMessage<span class="token punctuation">:</span> <span class="token string">&apos;&apos;</span><span class="token punctuation">,</span>  <span class="token comment">// &#x6821;&#x9A8C;&#x4E0D;&#x901A;&#x8FC7;&#x65F6;&#x7684;&#x63D0;&#x793A;&#x4FE1;&#x606F;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function">mounted</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment">// &#x5982;&#x679C;&#x6CA1;&#x6709;&#x4F20;&#x5165; prop&#xFF0C;&#x5219;&#x65E0;&#x9700;&#x6821;&#x9A8C;&#xFF0C;&#x4E5F;&#x5C31;&#x65E0;&#x9700;&#x7F13;&#x5B58;</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>prop<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">dispatch</span><span class="token punctuation">(</span><span class="token string">&apos;faForm&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;on-form-item-add&apos;</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// &#x8BBE;&#x7F6E;&#x521D;&#x59CB;&#x503C;&#xFF0C;&#x4EE5;&#x4FBF;&#x5728;&#x91CD;&#x7F6E;&#x65F6;&#x6062;&#x590D;&#x9ED8;&#x8BA4;&#x503C;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>initialValue <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>fieldValue<span class="token punctuation">;</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setRules</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    methods<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      <span class="token function">setRules</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">let</span> rules <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getRules</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>rules<span class="token punctuation">.</span>length<span class="token punctuation">)</span> <span class="token punctuation">{</span>
          rules<span class="token punctuation">.</span><span class="token function">every</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">rule</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
            <span class="token comment">// &#x5982;&#x679C;&#x5F53;&#x524D;&#x6821;&#x9A8C;&#x89C4;&#x5219;&#x4E2D;&#x6709;&#x5FC5;&#x586B;&#x9879;&#xFF0C;&#x5219;&#x6807;&#x8BB0;&#x51FA;&#x6765;</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span>isRequired <span class="token operator">=</span> rule<span class="token punctuation">.</span>required<span class="token punctuation">;</span>
          <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$on</span><span class="token punctuation">(</span><span class="token string">&apos;on-form-blur&apos;</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>onFieldBlur<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">$on</span><span class="token punctuation">(</span><span class="token string">&apos;on-form-change&apos;</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>onFieldChange<span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token comment">// &#x4ECE; Form &#x7684; rules &#x5C5E;&#x6027;&#x4E2D;&#xFF0C;&#x83B7;&#x53D6;&#x5F53;&#x524D; FormItem &#x7684;&#x6821;&#x9A8C;&#x89C4;&#x5219;</span>
      <span class="token function">getRules</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">let</span> formRules <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>form<span class="token punctuation">.</span>rules<span class="token punctuation">;</span>

        formRules <span class="token operator">=</span> formRules <span class="token operator">?</span> formRules<span class="token punctuation">[</span><span class="token keyword">this</span><span class="token punctuation">.</span>prop<span class="token punctuation">]</span> <span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span>

        <span class="token keyword">return</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span>formRules <span class="token operator">||</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token comment">// &#x91CD;&#x7F6E;&#x6570;&#x636E;</span>
      <span class="token function">resetField</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>validateState <span class="token operator">=</span> <span class="token string">&apos;&apos;</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>validateMessage <span class="token operator">=</span> <span class="token string">&apos;&apos;</span><span class="token punctuation">;</span>

        <span class="token keyword">this</span><span class="token punctuation">.</span>form<span class="token punctuation">.</span>model<span class="token punctuation">[</span><span class="token keyword">this</span><span class="token punctuation">.</span>prop<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span>initialValue<span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">
  <span class="token selector">.form-item-label-required:before</span> <span class="token punctuation">{</span>
    <span class="token property">content</span><span class="token punctuation">:</span> <span class="token string">&apos;*&apos;</span><span class="token punctuation">;</span>
    <span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token selector">.form-item-message</span> <span class="token punctuation">{</span>
    <span class="token property">color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<p>&#x81F3;&#x6B64;&#xFF0C;FormItem &#x4EE3;&#x7801;&#x5DF2;&#x7ECF;&#x5B8C;&#x6210;&#xFF0C;&#x4E0D;&#x8FC7;&#x5B83;&#x53EA;&#x5177;&#x6709;&#x5355;&#x72EC;&#x6821;&#x9A8C;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x53EA;&#x80FD;&#x5BF9;&#x81EA;&#x5DF1;&#x7684;&#x4E00;&#x4E2A;&#x8868;&#x5355;&#x7EC4;&#x4EF6;&#x9A8C;&#x8BC1;&#xFF0C;&#x4E0D;&#x80FD;&#x5BF9;&#x4E00;&#x4E2A;&#x8868;&#x5355;&#x57DF;&#x91CC;&#x7684;&#x6240;&#x6709;&#x7EC4;&#x4EF6;&#x4E00;&#x6B21;&#x6027;&#x5168;&#x90E8;&#x6821;&#x9A8C;&#x3002;&#x800C;&#x5B9E;&#x73B0;&#x5168;&#x90E8;&#x6821;&#x9A8C;&#x548C;&#x5168;&#x90E8;&#x91CD;&#x7F6E;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x8981;&#x5728; Form &#x4E2D;&#x5B8C;&#x6210;&#x3002;</p>
<h2 id="&#x5B9E;&#x73B0;&#x5168;&#x5C40;&#x6821;&#x9A8C;&#x548C;&#x91CD;&#x7F6E;"><a name="&#x5B9E;&#x73B0;&#x5168;&#x5C40;&#x6821;&#x9A8C;&#x548C;&#x91CD;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#&#x5B9E;&#x73B0;&#x5168;&#x5C40;&#x6821;&#x9A8C;&#x548C;&#x91CD;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5B9E;&#x73B0;&#x5168;&#x5C40;&#x6821;&#x9A8C;&#x548C;&#x91CD;&#x7F6E;</h2>
<p>&#x4E0A;&#x6587;&#x5DF2;&#x7ECF;&#x4ECB;&#x7ECD;&#x5230;&#xFF0C;&#x5728; Form &#x7EC4;&#x4EF6;&#x4E2D;&#xFF0C;&#x9884;&#x5148;&#x7F13;&#x5B58;&#x4E86;&#x5168;&#x90E8;&#x7684; FormItem &#x5B9E;&#x4F8B;&#xFF0C;&#x81EA;&#x7136;&#x4E5F;&#x80FD;&#x5728; Form &#x4E2D;&#x8C03;&#x7528;&#x5B83;&#x4EEC;&#x3002;&#x901A;&#x8FC7;&#x70B9;&#x51FB;&#x63D0;&#x4EA4;&#x6309;&#x94AE;&#x5168;&#x90E8;&#x6821;&#x9A8C;&#xFF0C;&#x6216;&#x70B9;&#x51FB;&#x91CD;&#x7F6E;&#x6309;&#x94AE;&#x5168;&#x90E8;&#x91CD;&#x7F6E;&#x6570;&#x636E;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x5728; Form &#x4E2D;&#xFF0C;&#x9010;&#x4E00;&#x8C03;&#x7528;&#x7F13;&#x5B58;&#x7684; FormItem &#x5B9E;&#x4F8B;&#x4E2D;&#x7684; validate &#x6216; resetField &#x65B9;&#x6CD5;&#x3002;&#x76F8;&#x5173;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-js"><span class="token comment">// form.vue&#xFF0C;&#x90E8;&#x5206;&#x4EE3;&#x7801;&#x7701;&#x7565;</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  <span class="token function">data</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">{</span>
      fields<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
    <span class="token punctuation">}</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  methods<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token comment">// &#x516C;&#x5F00;&#x65B9;&#x6CD5;&#xFF1A;&#x5168;&#x90E8;&#x91CD;&#x7F6E;&#x6570;&#x636E;</span>
    <span class="token function">resetFields</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">this</span><span class="token punctuation">.</span>fields<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token parameter">field</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
        field<span class="token punctuation">.</span><span class="token function">resetField</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">// &#x516C;&#x5F00;&#x65B9;&#x6CD5;&#xFF1A;&#x5168;&#x90E8;&#x6821;&#x9A8C;&#x6570;&#x636E;&#xFF0C;&#x652F;&#x6301; Promise</span>
    <span class="token function">validate</span><span class="token punctuation">(</span><span class="token parameter">callback</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token parameter">resolve</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
        <span class="token keyword">let</span> valid <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
        <span class="token keyword">let</span> count <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>fields<span class="token punctuation">.</span><span class="token function">forEach</span><span class="token punctuation">(</span><span class="token parameter">field</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
          field<span class="token punctuation">.</span><span class="token function">validate</span><span class="token punctuation">(</span><span class="token string">&apos;&apos;</span><span class="token punctuation">,</span> <span class="token parameter">errors</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>errors<span class="token punctuation">)</span> <span class="token punctuation">{</span>
              valid <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">++</span>count <span class="token operator">===</span> <span class="token keyword">this</span><span class="token punctuation">.</span>fields<span class="token punctuation">.</span>length<span class="token punctuation">)</span> <span class="token punctuation">{</span>
              <span class="token comment">// &#x5168;&#x90E8;&#x5B8C;&#x6210;</span>
              <span class="token function">resolve</span><span class="token punctuation">(</span>valid<span class="token punctuation">)</span><span class="token punctuation">;</span>
              <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> callback <span class="token operator">===</span> <span class="token string">&apos;function&apos;</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token function">callback</span><span class="token punctuation">(</span>valid<span class="token punctuation">)</span><span class="token punctuation">;</span>
              <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
          <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x5728;&#x4F7F;&#x7528;&#x4E2D;&#x5C31;&#x662F;&#x8FD9;&#x6837;&#x7684;</p>
<pre class="language-"><code class="lang-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>i-form</span> <span class="token attr-name">ref</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>form<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>i-form</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">@click</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>handleSubmit<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>&#x63D0;&#x4EA4;<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
  <span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
    methods<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      <span class="token function">handleSubmit</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>$refs<span class="token punctuation">.</span>form<span class="token punctuation">.</span><span class="token function">validate</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">valid</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
          <span class="token keyword">if</span> <span class="token punctuation">(</span>valid<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            window<span class="token punctuation">.</span><span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">&apos;&#x63D0;&#x4EA4;&#x6210;&#x529F;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
            window<span class="token punctuation">.</span><span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">&apos;&#x8868;&#x5355;&#x6821;&#x9A8C;&#x5931;&#x8D25;&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
</code></pre>
<p>&#x5B8C;&#x6574;&#x7684;&#x793A;&#x4F8B;&#x6E90;&#x7801;&#x53EF;&#x901A;&#x8FC7; <a href="https://github.com/YoungGary/faForm" target="_blank">GitHub</a> &#x67E5;&#x770B;</p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; YoungGary 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2021-09-09 22:08:17
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../vue/2.html" class="navigation navigation-prev " aria-label="Previous page: 2.手动实现broadcast和dispatch方法">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="./" class="navigation navigation-next " aria-label="Next page: JavaScript进阶">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"3.自己动手实现带校验的Form表单组件","level":"1.4.3","depth":2,"next":{"title":"JavaScript进阶","level":"1.5","depth":1,"path":"js/README.md","ref":"js/README.md","articles":[{"title":"1.Vue.js 3.0中的响应式","level":"1.5.1","depth":2,"path":"js/proxy.md","ref":"js/proxy.md","articles":[]},{"title":"2.Element UI 源码初探","level":"1.5.2","depth":2,"path":"js/el.md","ref":"js/el.md","articles":[]},{"title":"3.bind的模拟实现","level":"1.5.3","depth":2,"path":"js/bind.md","ref":"js/bind.md","articles":[]},{"title":"4.JS原型和原型链","level":"1.5.4","depth":2,"path":"js/proto.md","ref":"js/proto.md","articles":[]},{"title":"5.模拟实现call和apply","level":"1.5.5","depth":2,"path":"js/call.md","ref":"js/call.md","articles":[]},{"title":"6.使用Vue cli3搭建组件库并发布到 npm","level":"1.5.6","depth":2,"path":"js/ui.md","ref":"js/ui.md","articles":[]},{"title":"7.记一次基于qiankun的微前端的改造","level":"1.5.7","depth":2,"path":"js/microFE.md","ref":"js/microFE.md","articles":[]},{"title":"8.Git的使用","level":"1.5.8","depth":2,"path":"js/git.md","ref":"js/git.md","articles":[]}]},"previous":{"title":"2.手动实现broadcast和dispatch方法","level":"1.4.2","depth":2,"path":"vue/2.md","ref":"vue/2.md","articles":[]},"dir":"ltr"},"config":{"plugins":["theme-comscore","prism","-highlight","copy-code-button","search-pro","-search","-lunr","expandable-chapters","splitter","-sharing","tbfed-pagefooter","anchor-navigation-ex"],"styles":{},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy YoungGary 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prismjs/themes/prism-solarizedlight.css"],"lang":{"shell":"bash"}},"splitter":{},"search-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"theme-comscore":{},"copy-code-button":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"Gary","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Gary的小窝","language":"zh-hans","gitbook":"*","description":"Gary的小窝. 里面包含了个人撰写的技术文章"},"file":{"path":"js/form.md","mtime":"2021-09-09T14:08:17.739Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-09-09T14:10:10.930Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

